<template>
  <div class="app-container">
    <div style="padding-bottom: 1rem" align="right">
      <el-button @click="back">返回</el-button>
    </div>
    <el-table
      element-loading-text="Loading"
      :data="checkList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <el-table-column label="设备" align="center">
        <template slot-scope="scope">{{ scope.row.deviceCode }}</template>
      </el-table-column>
      <el-table-column label="扫码时间" align="center">
        <template slot-scope="scope">{{ scope.row.codeTime }}</template>
      </el-table-column>
      <el-table-column label="设备状态" align="center" prop="deviceStatus">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.deviceStatus == '设备正常' ? 'primary' : 'danger'"
            disable-transitions>{{scope.row.deviceStatus}}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="设备描述" align="center">
        <template slot-scope="scope">{{ scope.row.deviceSpec }}</template>
      </el-table-column>
      <el-table-column label="异常原因" align="center">
        <template slot-scope="scope">{{ scope.row.inventoryInfo }}</template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>
  </div>
</template>

<script>
  import $ from "@/api/equipInvent"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        checkList: [],
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        this.currentPage = 1
        $.inventoryTask({
          pageIndex: this.currentPage,
          pageSize: this.pageSize,
          taskId: this.$route.query.id
        }).then(res => {
          this.checkList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // for (let resKey in this.checkList) {
          //   if (resKey.deviceStatus=="1"){
          //
          //   }
          // }
          console.log(this.checkList)
        })
      },

      find(pageIndex) {
        $.inventoryTask({
          pageIndex: pageIndex,
          pageSize: this.pageSize,
          taskId: this.$route.query.id
        }).then(res => {
          this.checkList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },
      back() {
        this.$router.replace({
          path: "index",
        })
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

    }
  }
</script>
<style>
  .el-tooltip__popper {
    max-width: 700px
  }
</style>

